package com.com;

import java.util.concurrent.locks.StampedLock;

public class TestMainStampedLock implements Runnable {

	StampedLock locker = new StampedLock();
	
	public static void main(String[] args) {

		new Thread(new TestMainStampedLock()).start();
		new Thread(new TestMainStampedLock()).start();
		new Thread(new TestMainStampedLock()).start();
		new Thread(new TestMainStampedLock()).start();
	}
	
	public void print(int i){
		
		locker.asReadWriteLock().readLock().lock();
		try {
			if ( i == 10){
				return;
			}
			
			System.out.println(i);
			
			print(++i);
			
		} finally {
			locker.asReadWriteLock().readLock().unlock();
		}
		
	}

	@Override
	public void run() {
		System.out.println(Thread.currentThread().getName());
		print(0);
	}

}
